#!/usr/bin/env python
# encoding: utf-8
"""
Log.py

Created by Alakazam on 2008-05-26.
Copyright (c) 2008. All rights reserved.
"""

from time import time
from sys  import stdout

import psyco
psyco.full()

class Log(object):
  """This class handles simple console logging and performance calculations"""
  
  VERBOSE = True
  QUIET   = False
  
  def __init__(self, verbosity=None):
    self.verbosity = verbosity if verbosity != None else self.QUIET
  
  def __call__(self, text, flush=False, newline=True):
    if self.verbosity == self.VERBOSE:
      if newline:
        print text
      else:
        print text,
      
      if flush:
        stdout.flush()
  
  def start(self, text):
    if self.verbosity == self.VERBOSE:
      print " * ", text
      self.t = time()
  
  def stop(self):
    if self.verbosity == self.VERBOSE:
      print "...", round(time() - self.t, 2), 's'
  

if __name__ == '__main__':
  log = Log(Log.VERBOSE)
  
  log("foo")

